package com.ht.controller;
import java.util.Arrays;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ht.entity.TablesEntity;
import com.ht.service.ITablesService;
import com.ht.utils.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @author ht
 * @email ht035200@163.com
 * @date 2021-09-23 23:02:31
 */
@RestController
@RequestMapping("/generator/tables")
public class TablesController {
    @Resource
    ITablesService tablesServiceImpl;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam(name = "page", defaultValue = "1") Integer pageNo, @RequestParam(name = "limit", defaultValue = "10") Integer pageSize, @RequestParam(name = "key", required = false) String key) {
        return R.ok().put("page", tablesServiceImpl.queryPage(new Page<>(pageNo, pageSize), key));
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{tableCatalog}")
    public R info(@PathVariable("tableCatalog") String tableCatalog) {
        TablesEntity tables = tablesServiceImpl.getById(tableCatalog);
        return R.ok().put("tables", tables);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TablesEntity tables) {
        tablesServiceImpl.save(tables);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TablesEntity tables) {
        tablesServiceImpl.updateById(tables);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] tableCatalogs) {
        tablesServiceImpl.removeByIds(Arrays.asList(tableCatalogs));
        return R.ok();
    }

}
